<?php
/**
 * @author Paolo Bertuzzo
 * 
 */
namespace Catalog;

use Catalog\Controller\HomeController;
use Catalog\Controller\CategoryController;
use Catalog\Controller\ProductController;
use Utilities\Geolocation\GeolocationService;
use Catalog\Service\StoreService;
use Catalog\Data\StoreDao;
use Catalog\Helper\CategoryTreeHelper;
use Catalog\Helper\StoreSwitcherHelper;
use Catalog\Helper\BannerSliderHelper;
use Catalog\Helper\ProductsCarouselHelper;
use Catalog\Helper\CollectionsCarouselHelper;
use Catalog\Helper\CalloutHelper;
use Catalog\Helper\MenuHelper;
use Catalog\Helper\FooterHelper;
use Catalog\Helper\SocialCalloutHelper;
use Catalog\Helper\PaypalCalloutHelper;
use Catalog\Helper\ProductImagesCarouselHelper;
use Catalog\Form\WallStickerForm;
use Zend\Form\FormElementManager;
use Catalog\Form\Element\SizeElement;
use Catalog\Form\Element\FormElement;
use Catalog\Form\Element\ColorElement;
use Catalog\Form\Element\SubmitElement;
use Catalog\Controller\BasketController;

return array(
    
    // Custom forms elements
    'form_elements' => array(
        'invokables' => array(
            
            // Wall sticker product form
            'wall_sticker' => 'Catalog\Form\WallStickerForm'
        )
    ),
    
    // Module controllers
    'controllers' => array(
        
        // Factories for controllers. This solves dependencies injection
        'factories' => array(
            // Home controller
            'home' => function ($serviceManager)
            {
                $logger = $serviceManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $serviceManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                $configuration = $serviceManager->getServiceLocator()->get('Config');
                
                return new HomeController(new Service\ProductService(new Data\ProductDao($entityManager, $logger), 
                    new Data\CategoryDao($entityManager, $logger), 
                    new Data\LocalizedProductTextDao($entityManager, $logger), 
                    new Data\ProductImageDao($entityManager, $logger), 
                    new Data\ProductPriceDao($entityManager, $logger),
                    new Data\AttributeDao($entityManager, $logger)), 
                    new Service\CollectionService(new Data\CollectionDao($entityManager, $logger)), 
                    new GeolocationService($configuration['geolocation']['database_path']), 
                    new StoreService(new StoreDao($entityManager, $logger)), 
                    $configuration['list_per_page_items']['home_new_products']);
            },
            
            // Category controller
            'category' => function ($serviceManager)
            {
                $logger = $serviceManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $serviceManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                $configuration = $serviceManager->getServiceLocator()->get('Config');
                
                return new CategoryController(new Service\ProductService(new Data\ProductDao($entityManager, $logger), 
                    new Data\CategoryDao($entityManager, $logger), 
                    new Data\LocalizedProductTextDao($entityManager, $logger), 
                    new Data\ProductImageDao($entityManager, $logger), 
                    new Data\ProductPriceDao($entityManager, $logger), 
                    new Data\AttributeDao($entityManager, $logger)), 
                    new GeolocationService($configuration['geolocation']['database_path']), 
                    new StoreService(new StoreDao($entityManager, $logger)), 
                    $configuration['list_per_page_items']['category_products']);
            },
            
            // Product controller
            'product' => function ($serviceManager)
            {
                $logger = $serviceManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $serviceManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                $configuration = $serviceManager->getServiceLocator()->get('Config');
                
                return new ProductController(new Service\ProductService(new Data\ProductDao($entityManager, $logger), 
                    new Data\CategoryDao($entityManager, $logger), 
                    new Data\LocalizedProductTextDao($entityManager, $logger), 
                    new Data\ProductImageDao($entityManager, $logger), 
                    new Data\ProductPriceDao($entityManager, $logger), 
                    new Data\AttributeDao($entityManager, $logger)), 
                    new GeolocationService($configuration['geolocation']['database_path']), 
                    new StoreService(new StoreDao($entityManager, $logger)));
            },
            
            // Basket controller
            'basket' => function ($serviceManager)
            {
                $logger = $serviceManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $serviceManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                $configuration = $serviceManager->getServiceLocator()->get('Config');
                
            	return new BasketController(new Service\BasketService(new Data\BasketDao($entityManager, $logger),
                    new Data\BasketItemDao($entityManager, $logger),
                    new Data\LocalizedProductTextDao($entityManager, $logger),
                    new Data\ProductPriceDao($entityManager, $logger),
                    new Data\ProductImageDao($entityManager, $logger),
            	    new Data\AttributeValuePriceDao($entityManager, $logger),
                    new Data\AttributeDao($entityManager, $logger)),
            	    new GeolocationService($configuration['geolocation']['database_path']),
            	    new StoreService(new StoreDao($entityManager, $logger)));
            }
        )
    ),
    
    // View helpers
    'view_helpers' => array(
        
        'factories' => array(
            'formelement' => function($helperPluginManager) 
            {
            	return new FormElement();
            },

            'submit_element' => function ($helperPluginManager)
            {
            	return new SubmitElement();
            },
            
            'size_element' => function ($helperPluginManager)
            {
            	return new SizeElement();
            },

            'color_element' => function ($helperPluginManager)
            {
            	return new ColorElement();
            },
            
            'category_tree' => function ($helperPluginManager)
            {
                $logger = $helperPluginManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $helperPluginManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                
                return new CategoryTreeHelper(new Service\ProductService(new Data\ProductDao($entityManager, $logger), 
                    new Data\CategoryDao($entityManager, $logger), 
                    new Data\LocalizedProductTextDao($entityManager, $logger), 
                    new Data\ProductImageDao($entityManager, $logger), 
                    new Data\ProductPriceDao($entityManager, $logger),
                    new Data\AttributeDao($entityManager, $logger)));
            },
            
            'store_switcher' => function ($helperPluginManager)
            {
                $logger = $helperPluginManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $helperPluginManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                
                return new StoreSwitcherHelper(new Service\StoreService(new Data\StoreDao($entityManager, $logger)));
            },
            
            'banner_slider' => function ($helperPluginManager)
            {
                return new BannerSliderHelper();
            },
            
            'products_carousel' => function ($helperPluginManager)
            {
                return new ProductsCarouselHelper();
            },
            
            'collections_carousel' => function ($helperPluginManager)
            {
                return new CollectionsCarouselHelper();
            },
            
            'callout' => function ($helperPluginManager)
            {
                return new CalloutHelper();
            },
            
            'social_callout' => function ($helperPluginManager)
            {
                $configuration = $helperPluginManager->getServiceLocator()->get('Config');
                
                return new SocialCalloutHelper($configuration['social_network']);
            },
            
            'paypal_callout' => function ($helperPluginManager)
            {
                return new PaypalCalloutHelper();
            },
            
            'menu' => function ($helperPluginManager)
            {
                return new MenuHelper();
            },
            
            'footer' => function ($helperPluginManager)
            {
                return new FooterHelper();
            },
            
            'product_images_carousel' => function ($helperPluginManager)
            {
                return new ProductImagesCarouselHelper();
            }
        )
    ),
    
    // Module views
    'view_manager' => array(
        'template_path_stack' => array(
            'home' => __DIR__ . '/../view'
        ),
        'template_map' => array(
            'helper/category_tree' => __DIR__ . '/../view/catalog/helper/category_tree.phtml',
            'helper/banner_slider' => __DIR__ . '/../view/catalog/helper/banner_slider.phtml',
            'helper/store_switcher' => __DIR__ . '/../view/catalog/helper/store_switcher.phtml',
            'helper/products_carousel' => __DIR__ . '/../view/catalog/helper/products_carousel.phtml',
            'helper/collections_carousel' => __DIR__ . '/../view/catalog/helper/collections_carousel.phtml',
            'helper/callout' => __DIR__ . '/../view/catalog/helper/callout.phtml',
            'helper/paypal_callout' => __DIR__ . '/../view/catalog/helper/paypal_callout.phtml',
            'helper/social_callout' => __DIR__ . '/../view/catalog/helper/social_callout.phtml',
            'helper/menu' => __DIR__ . '/../view/catalog/helper/menu.phtml',
            'helper/footer' => __DIR__ . '/../view/catalog/helper/footer.phtml',
            'helper/paginator' => __DIR__ . '/../view/catalog/helper/paginator.phtml',
            'helper/product_images_carousel' => __DIR__ . '/../view/catalog/helper/product_images_carousel.phtml'
        )
    ),
    
    // Translations
    'translator' => array(
        'translation_file_patterns' => array(
            array(
                'type' => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern' => '%s.mo',
                'text_domain' => 'catalog'
            )
        )
    )
);